<template>
  <!--委外结算单-->
  <section class="page company-manage">
    <data-form :submitLoading="submitLoading" :model="queryModel" @onSearch="refreshData" :page="pageService">
      <template slot="inputs">
        <el-form-item label="委外方" prop="outsName">
          <!-- <el-select v-model="queryModel.outsName" placeholder="请选择" clearable>
            <el-option v-for="item in outSourceList" :key="item.id" :label="item.outsName" :value="item.id"></el-option>
          </el-select> -->
          <select-department :specialOptions="specialOptions" v-model="queryModel.outsName"></select-department>
        </el-form-item>
        <el-form-item label="批次号" prop="outBatch">
            <el-input v-model="queryModel.outBatch"></el-input>
        </el-form-item>
        <el-form-item label="委外时间" prop="date">
          <el-date-picker type="daterange" :editable="false" v-model="queryModel.date" placeholder="选择日期时间" clearable>
          </el-date-picker>
        </el-form-item>
      </template>
    </data-form>
    <data-box @onPageChange="refreshData" :selectionList.sync="selectionList" :data="dataList" :page="pageService">
      <template slot="buttons">
        <el-button @click="clickExport" v-auth = "1024">导出</el-button>
      </template>
      <template slot="columns">
        <el-table-column prop="outsourceName" label="委外方" :min-width="$helper.getColumnWidth(4)">
        </el-table-column>
        <el-table-column prop="outBatch" label="批次号" :min-width="$helper.getColumnWidth(4)">
        </el-table-column>
        <el-table-column prop="delegateDate" label="委外开始时间" :min-width="$helper.getColumnWidth(4)">
          <template slot-scope="scope">
            <span>{{scope.row.delegateDate | dateTimeFormat}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="createTime" label="委外到期时间" :min-width="$helper.getColumnWidth(4)">
          <template slot-scope="scope">
            <span>{{scope.row.endDate | dateTimeFormat}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="commissionAmount" label="佣金金额" :min-width="$helper.getColumnWidth(4)" show-overflow-tooltip>
        </el-table-column>
        <el-table-column label="操作" :min-width="$helper.getColumnWidth(3)">
          <template slot-scope="scope">
            <el-button @click="checkDetail(scope)" type="text">查看明细</el-button>
          </template>
        </el-table-column>
      </template>
    </data-box>
    <el-dialog title="查看明细" :center="true"  width="1500px"  :visible.sync="dialog.modifyManage">
      <modify-manage ref="modify-manage" @close="dialog.modifyManage = false" @refreshList="refreshData" :caseRow.sync="caseRow"></modify-manage>
    </el-dialog>
  </section>
</template>

<script lang="ts">
import Vue from "vue";
import Component from "vue-class-component";
import { Auth, Layout, Dependencies } from "~/core/decorator";
import { State, Getter } from "vuex-class";
import { OutsourceSettlevOucherService } from "~/services/domain-service/outsource-settle-manage-index.service";
import { OutsourceSettleManageService } from "~/services/domain-service/outsource-settle-manage.service";
import { PageService } from '~/utils/page.service';
import { SortService } from '~/utils/sort.service';
import DataForm from "~/components/common/data-form.vue";
import DataBox from "~/components/common/data-box.vue";
import modifyManage from '~/components/outsource-manage/outsource-settle-manage/modify-manage.vue'
import SelectDepartment from "~/components/business-component/select-department.vue";
import { OutsourceService } from "~/services/domain-service/outsource.service";
import { CommonService } from "~/utils/common.service";


// @Auth(1008)
@Layout("workspace")
@Component({
  components: {
    DataForm,
    DataBox,
    modifyManage,
    SelectDepartment
  }
})
export default class OutsourceSettleManageIndex extends Vue {
  @Dependencies(OutsourceSettlevOucherService)
  private outsourceSettlevOucherService: OutsourceSettlevOucherService;
  @Dependencies(PageService) private pageService: PageService;
  @Dependencies(SortService) private sortService: SortService;
  @Dependencies(OutsourceSettleManageService)
  private OutsourceSettleManageService: OutsourceSettleManageService;
  @Dependencies(OutsourceService) private outsourceService: OutsourceService;
  @State private outSourceList;


  private dialog: any = {
    modifyManage: false
  };
  private selectionList: any[] = [];
  // form 查询表单参数
   private queryModel: any = {
    outsName:'',
    outBatch:'',
    date:[], //委外时间起止
  }
  private outsNames: any[] = [];//受托方列表
  private submitLoading: any = true
  private dataList: any[] = [];
  private caseRow:any = {}; //查看或编辑某一条row
  private specialOptions:any[] = []
  private mounted() {
    this.refreshData();
    this.getOuterSource();
  }
  /**
   * 查询列表
   */
  private refreshData() {
    this.selectionList = []
    this.outsourceSettlevOucherService.
    getCaseSettlementSheetPageList(this.queryModel,this.pageService)
    .subscribe( data => {
        this.dataList = data;
        this.submitLoading = false
      }
    )
  }

  //获取委外部门不包括律所
  private getOuterSource() {
    this.outsourceService.getOuterSource().subscribe(
      data =>{ this.specialOptions = CommonService.generateTreeData(data, {
        keyName: 'id',
        parentKeyName: 'parentId'
      })
      // data =>{console.log(data,"data")
    })
  }
  /**
   * 导出委外对账单
   */
  private clickExport(){
    //需要导出的列表 ids
    const ids =this.selectionList? this.selectionList.map((v) => v.id):'';
    this.outsourceSettlevOucherService.
    exportSettlementSheet({ids})
    .subscribe( data => {
          this.$message.success("导出成功!");
          window.open(data.url);
      }
    )
  }

  private checkDetail(scope){
    this.dialog.modifyManage = true;
    this.caseRow = scope.row;
  }
}
</script>

<style lang="less">

</style>




